#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[405];
int cnt[5];
int dp[45][45][45][45];

int dfs(int x1, int x2, int x3, int x4) {
  if (dp[x1][x2][x3][x4] != -1) return dp[x1][x2][x3][x4];
  int t = x1 + x2 * 2 + x3 * 3 + x4 * 4;
  int& ans = dp[x1][x2][x3][x4];
  if (x1) ans = max(ans, dfs(x1 - 1, x2, x3, x4));
  if (x2) ans = max(ans, dfs(x1, x2 - 1, x3, x4));
  if (x3) ans = max(ans, dfs(x1, x2, x3 - 1, x4));
  if (x4) ans = max(ans, dfs(x1, x2, x3, x4 - 1));
  ans += a[t];
  // cout << x1 << ' ' << x2 << ' ' << x3 << ' ' << x4 << ' ' << ans << endl;
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 0, n - 1) cin >> a[i];
  rep(i, 1, m) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0][0][0] = 0;
  cout << dfs(cnt[1], cnt[2], cnt[3], cnt[4]) + a[0];
  return 0;
}